{
	template:`
	<a-page-header title="编辑" sub-title="表达式">
		<template #extra>
			<a-button type="primary" @click="doInput();">确定</a-button>
			<m-back @click="back(false);">关闭</m-back>
		</template>
		<a-card :hoverable="true" :bodyStyle="{padding:'0 20px 20px'}">
		    <a-row :gutter="16">
                <a-col :span="15">
		            <a-divider orientation="left">表达式</a-divider>
		            <a-select :options="temps" v-model:value="selectTemp" @select="selectTemps" show-search :filter-option="selectFilter" style="width:100%;" />
		            <div style="padding:8px 0;">
		                <template v-if="inputTemp">
                            <a-row type="flex">
                                <a-col flex="auto">
                                    <a-textarea v-model:value="inputTemp" placeholder="请输入表达式" auto-size/>
                                </a-col>
                                <a-col flex="72px" style="text-align:right;">
                                    <a-button type="primary" @click="doneInputTest();">确认</a-button>
                                </a-col>
                            </a-row>
		                </template>
		                <template v-else>
		                    <a-typography-link @click="inputTemp=inputTest;selectTemp='';">{{inputTest}}</a-typography-link>
		                </template>
		            </div>
                    <a-alert message="↑点击修改表达式，#{xxxx}为表达式参数，请在右侧设置。" type="info" />
                </a-col>
                <a-col :span="9">
		            <a-divider orientation="left">表达式参数</a-divider>
                    <a-tag v-for="(item,index) in inputParams" @click="selectTag(index,item)" :color="selectParam==item&&selectIndex==index?'#108ee9':'processing'" style="margin-bottom:8px;">{{item}}</a-tag>
                    <div v-if="selectParam">
                        <div v-for="(item,index) in selectOptions" style="padding-bottom:8px;">
                            <a-select :options="item" v-model:value="fields[index]" @select="getTableColumn(index)" show-search :filter-option="selectFilter" style="width:100%;" />
                        </div>
                        <div style="text-align:right;">
                            <a-space>
                                <a-button type="primary" @click="inputTableColumn();">确认</a-button>
                                <a-button @click="selectTag(selectIndex,selectParam);">重置</a-button>
                            </a-space>
                        </div>
			        </div>
                </a-col>
		    </a-row>
            <a-divider>表达式结果</a-divider>
            <div style="text-align:center;">
                <a-typography-text strong>{{resultTest}}</a-typography-text>&nbsp;
                <a-tag v-if="resultTest.indexOf('#{字段}')>=0" color="error">错误</a-tag>
            </div>
		</a-card>
	</a-page-header>
	`,
	props: ['localeZh','param','parentVue'],
	data:function(){
		return {
		    temps:[],
		    selectTemp:'',
		    inputTemp:'',
		    inputTest:'',
		    resultTest:'',
		    collectOid:'',
		    inputParams:[],
		    selectIndex:-1,
		    selectParam:'',
		    fields:[],
		    selectOptions:[],
		    tables:{},
		};
	},
	mounted(){
	    this.collectOid=this.param.collectOid;
	    if(this.param.temps){
	        for(var i=0;i<this.param.temps.length;i++){
	            var t=this.param.temps[i];
	            this.temps.push({key:t,value:t,label:t});
	        }
	    }
	    this.temps.push({key:'',value:'',label:'自定义'});
	    this.setInputTest(this.param.value||'true');
	},
	methods:{
	    selectTemps:function(item){
	        if(item){
	            this.inputTemp='';
	            this.setInputTest(item);
	        }else{
	            this.inputTemp=this.inputTest;
	        }
	    },
	    doneInputTest:function(){
	        if(this.inputTemp){
	            this.setInputTest(this.inputTemp.replace(/[\n\r]/g,' '));
	            this.inputTemp='';
	        }else{
	            this.remind().error("自定义表达式不能为空");
	        }
	    },
	    setInputTest:function(test){
            this.inputTest=test;
            var arr=this.inputTest.match(/\#\{.+?\}/g);
            if(!arr) arr=[];
            this.inputParams=arr;
            this.matchResultTest();
	    },
        selectTag:function(index,tag){
            if(this.selectParam&&this.selectParam!=this.getSelectValue()){
                this.$confirm({
                    title: '确认设置',
                    content: '当前设置未点确认，是否确认后在切换?',
                    onOk: function(){
                        this.inputTableColumn();
                        this.doSelectTag(index,tag);
                    }.bind(this),
                    onCancel: function(){
                        this.doSelectTag(index,tag);
                    }.bind(this)
                });
            }else{
                this.doSelectTag(index,tag);
            }
        },
        doSelectTag:function(index,tag){
            this.selectIndex=index;
            this.selectParam=tag;
            this.fields=tag.substring(2,tag.length-1).split(".");
            this.selectOptions=[];
            this.getTableMap();
        },
        getTableMap:function(){
			this.requestData('action/api/apiCollect/getCollectTable',
				{collectOid:this.collectOid},
				data=>{
					if(data.code==0){
					    var os=[];
					    for(var k in data.map){
					        var t=data.map[k];
					        var n=' : '+t.description+t.name;
					        this.tables[k]=t;
					        os.push({key:k,value:k,label:k+(k.indexOf(":")==0?'':n)});
					    }
					    this.selectOptions[0]=os;
					    if(this.fields[0]){
					        this.getTableColumn(0);
					    }
					}
				}
			);
        },
        getTableColumn:function(i){
            var a=this.fields[0];
            for(var n=1;n<this.fields.length&&n<=i;n++){
                a+='.'+this.fields[n];
            }
            var t=this.tables[a];
            if(t){
                this.selectOptions.splice(i+1);
                this.requestData('action/api/apiCollect/getTableColumn',
                    {tableOid:t.oid},
                    data=>{
                        if(data.code==0){
                            var os=[];
                            var has=false;
                            for(var m=0;m<data.list.length;m++){
                                var f=data.list[m];
                                if(f.modelTable&&f.modelTable.oid){
                                   this.tables[a+'.'+f.name]=f.modelTable;
                                }
                                os.push({key:f.name,value:f.name,label:(f.description||'')+f.name+' '+(f.modelTable.oid?f.modelTable.oid:'')});
                                if(this.fields.length>i&&this.fields[i+1]==f.name){
                                    has=true;
                                }
                            }
                            if(!has){
                                this.fields.splice(i+1);
                            }
                            this.selectOptions.push(os);
                            if(this.fields.length<this.selectOptions.length){
                                this.fields.push(this.selectOptions[this.selectOptions.length-1][0].key);
                            }
                            this.getTableColumn(i+1);
                        }
                    }
                );
            }else{
                this.selectOptions.splice(i+1);
                this.fields.splice(i+1);
            }
        },
        getSelectValue:function(){
            var a=this.fields[0];
            for(var n=1;n<this.fields.length;n++){
                a+='.'+this.fields[n];
            }
            return '#{'+a+'}';
        },
        inputTableColumn:function(){
            this.inputParams[this.selectIndex]=this.getSelectValue();
            this.selectParam='';
            this.selectIndex=-1;
	        this.matchResultTest();
        },
        matchResultTest:function(){
            this.resultTest=this.inputTest;
            var arr=this.inputTest.match(/\#\{.+?\}/g);
            if(!arr) arr=[];
            for(var i=0;i<arr.length;i++){
                this.resultTest=this.resultTest.replace(arr[i],this.inputParams[i]);
            }
        },
	    doInput:function(){
	        if(this.selectParam){
	            this.remind().error("请选确认下面设置");
	            return;
	        }
	        if(this.resultTest.indexOf('#{字段}')>=0){
	            this.remind().error("请修改未设置的字段");
	            return;
	        }
	        this.back(true,this.resultTest);
	    }
	}
}